package org.tooyoung.fourone.user.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.tooyoung.fourone.R;

import java.util.List;

/**
 * Created by Administrator on 2016/11/9.
 */

public class MyListviewAdapter extends BaseAdapter {
    private List<String> mList;
    private Context mContext;

    public MyListviewAdapter(Context context, List<String> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public String getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_item,parent,false);
            convertView.setTag(new ViewHolder(convertView));
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        switch (position){
            case 0:
                holder.textview.setText("用户名:"+mList.get(position));
                holder.textview.setBackgroundResource(R.drawable.e1);
                break;
            case 1:
                holder.textview.setText("所在城市:"+mList.get(position));
                holder.textview.setBackgroundResource(R.drawable.e2);
                break;
            case 2:
                holder.textview.setText("详细地址:"+mList.get(position));
                holder.textview.setBackgroundResource(R.drawable.e3);
                break;
            case 3:
                holder.textview.setText("电话:"+mList.get(position));
                holder.textview.setBackgroundResource(R.drawable.e4);
                break;
            case 4:
                holder.textview.setText("电子邮箱:"+mList.get(position));
                holder.textview.setBackgroundResource(R.drawable.e5);
                break;
        }

        return convertView;
    }

    public static class ViewHolder{
        private TextView textview;
        public ViewHolder(View convertView){
            textview = ((TextView) convertView.findViewById(R.id.item_information));
        }
    }
}
